layui.config({
    base: CXL.ctxPath + '/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['index', 'form','laydate'], function(){
    var form = layui.form;
    var admin = layui.admin;
    var table = layui.table;
    var laydate = layui.laydate;

    var $ = layui.$;

    var Page = {
        tableId: 'task-info',
        url:CXL.ctxPath + '/sys/addTask/infoList',
        queryUrl:CXL.ctxPath + '/sys/addTask/taskDetailIndex',
        initColumn:function(){
            return [[
                {type:'checkbox',name:'choose',title:'choose',width:'3%'},
                {type : 'numbers',title : '序号',width:'3%'},
                {field:'idKey',title:'任务号',width:'5%'},
                {field:'tankCarNo',title:'槽车号',width:'8%'},
                {field:'materialNum',title:'子任务数',width:'5%'},
                {field:'status',title:'任务状态',width:'8%',templet:"#online-status"},
                {field:'errMsg',title:'错误信息',width:'15%'},
                {field:'distributeDate',title:'下发时间',width:'15%'},
                {field:'startDate',title:'开始时间',width:'15%'},
                {field:'completeDate',title:'完成时间',width:'15%'},
                {title:'操作',width:'5%',toolbar: '#sys-task-tool'}
            ]];
        },
    };



    table.render({
        elem:'#' + Page.tableId,
        url:Page.url,
        height:'500px',
        page:true,
        limits:[3,5,7,10,20,30],
        limit:10,
        autoSort:false,
        where: Page.where,
        cols:Page.initColumn()
    });


    laydate.render({
        elem:'#distStartDateStr',
    })

    laydate.render({
        elem:'#distEndDateStr',
    });

    laydate.render({
        elem:'#comStartDateStr',
    })

    laydate.render({
        elem:'#comEndDateStr',
    });


    Page.resetAction = function (){
        $(".layui-input").val('');
        Page.searchAction();
    };

    Page.searchAction = function (){
        var tankCarNo = $('#tankCarNo').val();
        var distStartDateStr = $('#distStartDateStr').val();
        var distEndDateStr = $('#distEndDateStr').val();
        var comStartDateStr = $('#comStartDateStr').val();
        var comEndDateStr = $('#comEndDateStr').val();

        var param = {tankCarNO:tankCarNo,distStartDateStr:distStartDateStr,distEndDateStr:distEndDateStr,comStartDateStr:comStartDateStr,comEndDateStr:comEndDateStr};
        table.render({
            elem:'#' + Page.tableId,
            url:Page.url,
            height:'500px',
            page:true,
            limits:[3,5,7,10,20,30],
            limit:10,
            autoSort:false,
            where: param,
            cols:Page.initColumn()
        });

    };

    $('#btnSearch').click(function (){
        Page.searchAction();
    });


    $('#btnReset').click(function (){
        Page.resetAction();
    });

    /**
     * 编辑
     */
    Page.openDetail = function (data) {
        layer.open({
            type : 2,
            title : '任务详情',
            shadeClose : true,
            shade : 0.8,
            area: ['1100px', '700px'],
            content : Page.queryUrl + '?taskId=' + data.idKey,
            btn : [ '确定', '取消' ],
        });
    };


    /**
     * 表头工具栏
     */
    table.on('tool(' + Page.tableId + ')', function(obj){
        //获得当前行数据
        var data = obj.data;
        //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        var layEvent = obj.event;

        //编辑操作
        if(layEvent === 'detail'){
            Page.openDetail(data);
        }
    });




})